package it.hive.model.domain.io;

import it.hive.io.settings.beans.Impostazione;

import java.util.HashMap;
import java.util.Properties;

public class DefaultDownloadDirectory implements Impostazione {
	public static final String PREFIX = "defaultDownloadDirectory.";
	public static final String DEFAULT_DIRECTORY = "pathDefaultDirectory";
	public static final String FLAG_USA_SOLO_DEFAULT_DIRECTORY = "usaSoloDefaultDirectory";

	private String pathDefaultDirectory;
	private boolean usaSoloDefaultDirectory;

	public String getPathDefaultDirectory() {
		return pathDefaultDirectory;
	}

	public void setPathDefaultDirectory(String pathDefaultDirectory) {
		this.pathDefaultDirectory = pathDefaultDirectory;
	}

	public boolean usaSoloDefaultDirectory() {
		return usaSoloDefaultDirectory;
	}

	public void setUsaSoloDefaultDirectory(boolean usaSoloDefaultDirectory) {
		this.usaSoloDefaultDirectory = usaSoloDefaultDirectory;
	}

	@Override
	public HashMap<? extends Object, ? extends Object> getSettingsMap() {
		HashMap<String, String> settingsMap = new HashMap<>();
		if (pathDefaultDirectory != null) {
			settingsMap.put(PREFIX.concat(DEFAULT_DIRECTORY), pathDefaultDirectory);
		}
		settingsMap.put(PREFIX.concat(FLAG_USA_SOLO_DEFAULT_DIRECTORY), String.valueOf(usaSoloDefaultDirectory));
		return settingsMap;
	}

	@Override
	public void init(Properties propertiesFile) {
		if (propertiesFile.containsKey(PREFIX.concat(DEFAULT_DIRECTORY))) {
			pathDefaultDirectory = propertiesFile.getProperty(PREFIX.concat(DEFAULT_DIRECTORY));
		}
		if (propertiesFile.containsKey(PREFIX.concat(FLAG_USA_SOLO_DEFAULT_DIRECTORY))) {
			usaSoloDefaultDirectory = Boolean.valueOf(propertiesFile.getProperty(PREFIX.concat(FLAG_USA_SOLO_DEFAULT_DIRECTORY)));
		}

	}

}
